//100236.统计以给定字符开头和结尾的子字符串总数
//https://leetcode.cn/problems/count-substrings-starting-and-ending-with-given-character/
class Solution {
public:
    long long countSubstrings(string s, char c) {
        int n = s.size();
        long long sum = 0;
        for (int i = 0; i < n; ++i) 
            if (s[i] == c) ++sum;

        long long ret = sum;
        for (long long i = sum-1; i >= 1; --i) ret += i;

        return ret;
    }
};